var links = [];
var casper = require('casper').create();

function getLinks() {
    var links = document.querySelectorAll('div[name="repositoryPath"] a');
    return Array.prototype.map.call(links, function (e) {
        return e.getAttribute('href');
    });
}

casper.options.waitTimeout = 2 * 60 * 1000;

casper.start('http://nexus.oa.yitopapp.com/#nexus-search;quick~cxy', function () {
    // Wait for the page to be loadedcasperjs
    // this.waitForText("cxydevice-redis-");

    this.waitForSelector('div[name="repositoryPath"]')
    // this.waitForSelector('div[id="ext-comp-1068"]')
    // this.waitForSelector('form[action="/search"]');
});

casper.then(function () {
    // aggregate results for the 'casperjs' search
    links = this.evaluate(getLinks);

    // now search for 'phantomjs' by filling the form again
});

casper.then(function () {
    // aggregate results for the 'phantomjs' search
    links = links.concat(this.evaluate(getLinks));
});

casper.run(function () {
    // echo results in some pretty fashion
    this.echo(this.getHTML());
    this.echo(links.length + ' links found:');
    this.echo(' - ' + links.join('\n - ')).exit();
});